import {expect} from 'chai'
import {describe} from 'mocha'
import  * as redline from '../../src/redline'
import {Error, RedlineInfo} from '../../src/redline'
describe('测试 redline check', () => {

    it('测试有红线 大于返回false',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"ge","threshold":2}]');
        const result = redline.redlineCheckResult(redlines,"sasa",1);
        expect(result).equal(false)
    })

    it('测试有红线 大于返回true',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"ge","threshold":2.1}]');
        const result = redline.redlineCheckResult(redlines,"sasa",3);
        expect(result).equal(true)
    })

    it('测试有红线 小于返回true',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"le","threshold":2.1}]');
        const result = redline.redlineCheckResult(redlines,"sasa",1.1);
        expect(result).equal(true)
    })
    it('测试有红线 小于返回false',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"le","threshold":2.1}]');
        const result = redline.redlineCheckResult(redlines,"sasa",3);
        expect(result).equal(false)
    })
    it('测试有红线 等于返回true',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"eq","threshold":2.1}]');
        const result = redline.redlineCheckResult(redlines,"sasa",2.1);
        expect(result).equal(true)
    })
    it('测试有红线 等于返回false',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"eq","threshold":2.1}]');
        const result = redline.redlineCheckResult(redlines,"sasa",2.12);
        expect(result).equal(false)
    })

    it('测试有红线,threshold 为数字字符串,大于返回true',  () => {
        const redlines = JSON.parse('[{"key":"sasa","type":"ge","threshold":"2.1"}]');
        const result = redline.redlineCheckResult(redlines,"sasa",3);
        expect(result).equal(true)
    })

    it('测试有红线,threshold 为非数字字符串,大于返回false',  () => {
        const redlines = JSON.parse(`[{"key":"sasa","type":"ge","threshold":"\${abc}"}]`);
        const result = redline.redlineCheckResult(redlines,"sasa",3);
        expect(result).equal(false)
    })
})



describe('redlineCheck', () => {

    it('redlineCheck with right threshold retrun true',  () => {
        const redlineInfo : RedlineInfo = {
            readlineResults: [
                {
                    key: "key",
                    style: Error,
                    title: "key_title",
                    value: 2.5
                }
            ],
            title: "r_title",
            reportUrl: "reportUrl"
        }
        const checkRedlines = `[{"key":"key","type":"ge","threshold":"2.0"}]`;
        const result = redline.redlineCheck(redlineInfo, checkRedlines);
        expect(result).equal(true)
    })

    it('redlineCheck with right threshold retrun true',  () => {
        const redlineInfo : RedlineInfo = {
            readlineResults: [
                {
                    key: "key",
                    style: Error,
                    title: "key_title",
                    value: 2.5
                }
            ],
            title: "r_title",
            reportUrl: "reportUrl"
        }
        const checkRedlines = `[{"key":"key","type":"ge","threshold":"\${abc}"}]`;
        const result = redline.redlineCheck(redlineInfo, checkRedlines);
        expect(result).equal(false)
    })
})